package mqpaydemo.paydemo.mq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Description:
 * @Author: liujinsheng
 * @Date: 2021/9/10.
 */
@Component
public class Send {
    @Resource
    RabbitTemplate rabbitTemplate;
    @Resource
    Environment env;
    public void send() {
        String messageId = String.valueOf(UUID.randomUUID());
        String messageData = "测试消息!";
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> map = new HashMap<>();
        map.put("messageId", messageId);
        map.put("messageData", messageData);
        map.put("createTime", createTime);
        rabbitTemplate.convertAndSend("exchange","topic.xxx",map);
    }
}
